$(function() {
    load();
});

function load(){
    $("#inputbyUser").css('display','none');
    $("#showmul").css('display','none');
   $("#couserDiv").css('display','none');
   $("#FAndTF").css('display','none');
    $("#sub").css('display','none');

}
function initDataGrid(){

    $('#teachermulbox').datagrid({
        width:'99.5%',
        height:400,
        remoteSort:false,
        iconCls : 'icon-search',
        columns : [[
            {
                field : 'ID',

                checkbox : true
            },
            {
                field : 'Title',
                title : '题目',
                align:'center',
                width:'320px',
                sortable:true,
                formatter:dwxx_formattertoothers
            },
            {
                field : 'difficulty',
                title : '题目难度',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },
            {
                field : 'college',
                title : '学院',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },
            {
                field : 'dept',
                title : '专业',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },
            {
                field : 'CouserName',
                title : '课程',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },
            {
                field : 'describes',
                title : '详情',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },

            {
                field : '_operate',
                title : '操作',
                width:'180px',
                align:'center',
                sortable:true,
                formatter:function(value,row,index){
                    var obj = JSON.stringify(row.ID);
                    return "<div style='color: blue;background-color:#EEEEE0'><a href='#' name='opera' onclick='openmul("+obj+")' class='easyui-linkbutton' ></a>|<a href='#' name='opera2' onclick='updateboxmul("+obj+")' class='easyui-linkbutton' ></a></div>"
                }
            },

        ]],
        onLoadSuccess:function(data){
            $("a[name='opera']").linkbutton({text:'详情',plain:true,iconCls:'icon-search'});
            $("a[name='opera2']").linkbutton({text:'修改',plain:true,iconCls:'icon-edit'});
        },
        rownumbers:true,
        pagination:true,
    });
    findmul();

    //加载下拉框
    $("#mul_col").combobox(
        {
            url:'show/getallcol',
            type:'post',
            valueField:'collegeid',
            textField:'college',

            panelWidth: 'auto',
            panelHeight: 'auto',
            filter: function(q, row){
                var opts = $(this).combobox('options');
                return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
            }
        }
    );

    $("#mul_dept").combobox({
        url:'show/dept',
        type:'post',
        valueField:'deptid',
        textField:'dept',

        panelWidth: 'auto',
        panelHeight: 'auto',
        filter: function(q, row){
            var opts = $(this).combobox('options');
            return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
        }
    });

    $('#mul_couser').combobox({
        url:'show/getCouserss',
        type:'post',
        valueField:'ID',
        textField:'CouserName',

        panelWidth: 'auto',
        panelHeight: 'auto',
        filter: function(q, row){
            var opts = $(this).combobox('options');
            return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
        }
    });

}
function findmul() {
    var opts = $('#teachermulbox').datagrid("options");
    var col = $("#mul_col").combobox('getValue')==null?"":$("#mul_col").combobox('getValue');
    var dept = $("#mul_dept").combobox('getValue')==null?"":$("#mul_dept").combobox('getValue');
    var couser = $("#mul_couser").combobox('getValue')==null?"":$("#mul_couser").combobox('getValue');
    var nd = $("#mul_nd").combobox('getValue')==null?"":$("#mul_nd").combobox('getValue');
    if(null == opts.url||""==opts.url){
        opts.url = '/teacher/findmul';
    }
    $('#teachermulbox').datagrid('load', {
        col:col,
        dept:dept,
        couser:couser,
        nd:nd
    });
}
function delmul(){

    var checkedItems = $('#teachermulbox').datagrid('getSelections');
    if(checkedItems.length <= 0) {
        $.messager.alert('消息', "请选择一条数据！");
        return;
    }
    jQuery.messager.confirm('提示:', '删除后不可恢复,确定要操作！', function (event) {
        if (event) {
            var array = new Array()
            for(var i=0;i<checkedItems.length;i++){
                var obj = new Object();
                obj.ID = checkedItems[i].ID == null?"": checkedItems[i].ID+"";
                console.info(obj.ID);
                array.push(obj);

            }

            $.ajax({
                url : "/teacher/delmul",
                type : "post",
                dataType : "json",
                data : {datas:JSON.stringify(array)},
                success : function(data) {
                    findmul();
                    $.messager.alert("消息",data);
                }
            });

        }});
}
function initDataGridFandTF(){

    $('#FAndTFbox').datagrid({
        width:'99.5%',
        height:408,
        remoteSort:false,
        iconCls : 'icon-search',
        columns : [[
            {
                field : 'id',

                checkbox : true
            },
            {
                field : 'content',
                title : '题目',
                align:'center',
                width:'320px',
                sortable:true,
                formatter:dwxx_formattertoothers
            },
            {
                field : 'type',
                title : '题目类型',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },
            {
                field : 'difficulty',
                title : '题目难度',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },
            {
                field : 'college',
                title : '学院',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },
            {
                field : 'dept',
                title : '专业',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },
            {
                field : 'CouserName',
                title : '课程',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },
            {
                field : 'describes',
                title : '详情',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },

            {
                field : '_operate',
                title : '操作',
                width:'180px',
                align:'center',
                sortable:true,
                formatter:function(value,row,index){
                    var obj = JSON.stringify(row.id);
                    return "<div style='color: blue;background-color:#EEEEE0'><a href='#' name='opera' onclick='openFAndTF("+obj+")' class='easyui-linkbutton' ></a>|<a href='#' name='opera2' onclick='updateboxFAndTF("+obj+")' class='easyui-linkbutton' ></a></div>"
                }
            },

        ]],
        onLoadSuccess:function(data){
            $("a[name='opera']").linkbutton({text:'详情',plain:true,iconCls:'icon-search'});
            $("a[name='opera2']").linkbutton({text:'修改',plain:true,iconCls:'icon-edit'});
        },
        rownumbers:true,
        pagination:true,
    });

    findFAndTF();

    //加载下拉框
    $("#ft_col").combobox(
        {
            url:'show/getallcol',
            type:'post',
            valueField:'collegeid',
            textField:'college',

            panelWidth: 'auto',
            panelHeight: 'auto',
            filter: function(q, row){
                var opts = $(this).combobox('options');
                return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
            }
        }
    );

    $("#ft_dept").combobox({
        url:'show/dept',
        type:'post',
        valueField:'deptid',
        textField:'dept',

        panelWidth: 'auto',
        panelHeight: 'auto',
        filter: function(q, row){
            var opts = $(this).combobox('options');
            return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
        }
    });

    $('#ft_couser').combobox({
        url:'show/getCouserss',
        type:'post',
        valueField:'ID',
        textField:'CouserName',

        panelWidth: 'auto',
        panelHeight: 'auto',
        filter: function(q, row){
            var opts = $(this).combobox('options');
            return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
        }
    });
}

function findFAndTF() {
    var opts = $('#FAndTFbox').datagrid("options");
    if(null == opts.url||""==opts.url){
        opts.url = '/teacher/findFAndTF';
    }

    var col = $("#ft_col").combobox('getValue')==null?"":$("#ft_col").combobox('getValue');
    var dept = $("#ft_dept").combobox('getValue')==null?"":$("#ft_dept").combobox('getValue');
    var couser = $("#ft_couser").combobox('getValue')==null?"":$("#ft_couser").combobox('getValue');
    var nd = $("#tf_nd").combobox('getValue')==null?"":$("#tf_nd").combobox('getValue');
    var lx = $("#tf_lx").combobox('getValue')==null?"":$("#tf_lx").combobox('getValue');

    $('#FAndTFbox').datagrid('load', {
        col:col,
        dept:dept,
        couser:couser,
        nd:nd,
        lx:lx
    });
}
function delFAndTF(){
    var checkedItems = $('#FAndTFbox').datagrid('getSelections');
    if(checkedItems.length <= 0) {
        $.messager.alert('消息', "请选择一条数据！");
        return;
    }
    jQuery.messager.confirm('提示:', '删除后不可恢复,确定要操作！', function (event) {
        if (event) {
            var array = new Array()
            for(var i=0;i<checkedItems.length;i++){
                var obj = new Object();
                obj.ID = checkedItems[i].id == null?"": checkedItems[i].id+"";
                console.info(obj.ID);
                array.push(obj);

            }

            $.ajax({
                url : "/teacher/delfandtf",
                type : "post",
                dataType : "json",
                data : {datas:JSON.stringify(array)},
                success : function(data) {
                    $.messager.alert("消息",data);
                    findFAndTF();

                }
            });

        }});
}
function openFAndTF (msg) {

    $.ajax({
        url : "/teacher/getftandfmsg",
        type : "post",
        dataType : "json",
        data : {id:msg},
        success : function(msg) {
            $("#spantftitle").html(msg.content);
            $("#detailtf").window('open')
        }
    });
}
function updateboxFAndTF ( msg){

    $.ajax({
        url : "/teacher/getftandfmsg",
        type : "post",
        dataType : "json",
        data : {id:msg},
        success : function(msg) {

            console.info(msg);
            $("#tandtf_col_edit").combobox({
                url:'show/getallcol',
                type:'post',
                valueField:'collegeid',
                textField:'college',
                editable:false,
                panelWidth: 'auto',
                panelHeight: 'auto',
                filter: function(q, row){
                    var opts = $(this).combobox('options');
                    return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
                }
            });
            $("#tandtf_edpt_edit").combobox({
                url:'show/dept',
                type:'post',
                valueField:'deptid',
                textField:'dept',
                editable:false,
                panelWidth: 'auto',
                panelHeight: 'auto',
                filter: function(q, row){
                    var opts = $(this).combobox('options');
                    return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
                },

            });

            $('#tandtf_couser_edit').combobox({
                url:'show/getCouserss',
                type:'post',
                valueField:'ID',
                textField:'CouserName',
                editable:false,
                panelWidth: 'auto',
                panelHeight: 'auto',
                filter: function(q, row){
                    var opts = $(this).combobox('options');
                    return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
                }
            });

            //回显


            $("#spantitle_fantf_edit").val(msg.content);
            $("#fandtf_deit_ans").val(msg.ans)
            $("#tandtf_col_edit").combobox('setValue',msg.collegeid);
            $("#tandtf_edpt_edit").combobox('setValue',msg.deptid);
            $("#tandtf_couser_edit").combobox('setValue',msg.courseid);
            $("#nddj_fandtf_edit").combobox('setValue',msg.difficulty);
            $("#tandtf_edit_des").val(msg.describes);
            $("#update_tandtf_id").val(msg.id);
            $('#detailstandtf_edit').window('open');

        }
    });


}


function save_edit_tandtf_des(){

    var id=$("#update_tandtf_id").val()==null?"":$("#update_tandtf_id").val();
    var title = $("#spantitle_fantf_edit").val()==null?"":$("#spantitle_fantf_edit").val();
    var des = $("#tandtf_edit_des").val()==null?"":$("#tandtf_edit_des").val().replace(/\s*/g,"").replace(/,/g, "").replace(/，/g, "");
    var col = $("#tandtf_col_edit").combobox('getValue')==null?"":$("#tandtf_col_edit").combobox('getValue');
    var dept = $("#tandtf_edpt_edit").combobox('getValue')==null?"":$("#tandtf_edpt_edit").combobox('getValue');
    var couser = $("#tandtf_couser_edit").combobox('getValue')==null?"":$("#tandtf_couser_edit").combobox('getValue');
    var nd = $("#nddj_fandtf_edit").combobox('getValue')==null?"":$("#nddj_fandtf_edit").combobox('getValue');
    var ans = $("#fandtf_deit_ans").val()==null?"":$("#fandtf_deit_ans").val();

    var obj = new Object();

    if(title==''){
        $.messager.alert("消息",'题目不可以为空');
        return;
    }
    obj.ID=id;
    obj.title=title;
    obj.des=des;
    obj.col=col;
    obj.dept=dept;
    obj.couser=couser;
    obj.nd=nd;
    obj.ans=ans;

    $.ajax({
        url : "/teacher/updatetfandlab",
        type : "post",
        dataType : "json",
        data : {datas:JSON.stringify(obj)},
        success : function(data) {
            if (data=="成功") {
                $.messager.alert("消息",'修改成功');
                findFAndTF();
                $('#detailstandtf_edit').window('close');
            }else {
                $.messager.alert("消息",'修改未成功');
            }
        }
    });

}
function dwxx_formatter(value, row){

    return "<lable title='"+value+"'>"+value+"</lable>"
}
function dwxx_formattertoothers(value){
    value=value.replace(/[<>"&]/g, function(match, pos, originalText){
        switch(match){
            case "<": return "&lt;";
            case ">":return "&gt;";
            case "&":return "&amp;";
            case "\"":return "&quot;";

        }
    });



    return "<lable>"+value+"</lable>"
}
function initDataGridsub(){

    $('#subbox').datagrid({
        width:'99.5%',
        height:408,
        remoteSort:false,
        iconCls : 'icon-search',
        columns : [[
            {
                field : 'ID',

                checkbox : true
            },
            {
                field : 'content',
                title : '题目',
                align:'center',
                width:'320px',
                sortable:true,
                formatter:dwxx_formattertoothers
            },
            {
                field : 'difficulty',
                title : '题目难度',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },
            {
                field : 'college',
                title : '学院',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },
            {
                field : 'dept',
                title : '专业',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },
            {
                field : 'CouserName',
                title : '课程',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },
            {
                field : 'describes',
                title : '详情',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },

            {
                field : '_operate',
                title : '操作',
                width:'180px',
                align:'center',
                sortable:true,
                formatter:function(value,row,index){
                    var obj = JSON.stringify(row.id);
                    return "<div style='color: blue;background-color:#EEEEE0'><a href='#' name='opera' onclick='opensub("+obj+")' class='easyui-linkbutton' ></a>|<a href='#' name='opera2' onclick='updateboxsub("+obj+")' class='easyui-linkbutton' ></a></div>"
                }
            },

        ]],
        onLoadSuccess:function(data){
            $("a[name='opera']").linkbutton({text:'详情',plain:true,iconCls:'icon-search'});
            $("a[name='opera2']").linkbutton({text:'修改',plain:true,iconCls:'icon-edit'});
        },
        rownumbers:true,
        pagination:true,
    });

    //加载下拉框
    $("#ans_col").combobox(
        {
            url:'show/getallcol',
            type:'post',
            valueField:'collegeid',
            textField:'college',
            panelWidth: 'auto',
            panelHeight: 'auto',
            filter: function(q, row){
                var opts = $(this).combobox('options');
                return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
            }
        }
    );

    $("#ans_dept").combobox({
        url:'show/dept',
        type:'post',
        valueField:'deptid',
        textField:'dept',
        panelWidth: 'auto',
        panelHeight: 'auto',
        filter: function(q, row){
            var opts = $(this).combobox('options');
            return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
        }
    });

    $('#ans_couser').combobox({
        url:'show/getCouserss',
        type:'post',
        valueField:'ID',
        textField:'CouserName',
        panelWidth: 'auto',
        panelHeight: 'auto',
        filter: function(q, row){
            var opts = $(this).combobox('options');
            return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
        }
    });
    findsub();
}

function findsub() {
    var opts = $('#subbox').datagrid("options");
    if(null == opts.url||""==opts.url){
        opts.url = '/teacher/findans';
    }
    var col = $("#ans_col").combobox('getValue')==null?"":$("#ft_col").combobox('getValue');
    var dept = $("#ans_dept").combobox('getValue')==null?"":$("#ft_dept").combobox('getValue');
    var couser = $("#ans_couser").combobox('getValue')==null?"":$("#ft_couser").combobox('getValue');
    var nd = $("#ans_nd").combobox('getValue')==null?"":$("#tf_nd").combobox('getValue');

    $('#subbox').datagrid('load', {
        col:col,
        dept:dept,
        couser:couser,
        nd:nd
    });
}

function delANS(){
    var checkedItems = $('#subbox').datagrid('getSelections');
    if(checkedItems.length <= 0) {
        $.messager.alert('消息', "请选择一条数据！");
        return;
    }
    jQuery.messager.confirm('提示:', '删除后不可恢复,确定要操作！', function (event) {
        if (event) {
            var array = new Array()
            for(var i=0;i<checkedItems.length;i++){
                var obj = new Object();
                obj.ID = checkedItems[i].id == null?"": checkedItems[i].id+"";
                console.info(obj.ID);
                array.push(obj);

            }

            $.ajax({
                url : "/teacher/delANS",
                type : "post",
                dataType : "json",
                data : {datas:JSON.stringify(array)},
                success : function(data) {
                    $.messager.alert("消息",data);
                    findsub();

                }
            });

        }});
}
function opensub (msg){

    $.ajax({
        url : "/teacher/findsubmsg",
        type : "post",
        dataType : "json",
        data : {id:msg},
        success : function(msg) {
            console.info(msg);
            $("#spananstitle").html(msg.content);
            $("#detailans").window('open');
        }
    });


}
function updateboxsub (msg){
    console.info(msg)
    $.ajax({
        url : "/teacher/findsubmsg",
        type : "post",
        dataType : "json",
        data : {id:msg},
        success : function(msg) {

            console.info(msg)
            $("#tandans_col_edit").combobox({
                url:'show/getallcol',
                type:'post',
                valueField:'collegeid',
                textField:'college',
                editable:false,
                panelWidth: 'auto',
                panelHeight: 'auto',
                filter: function(q, row){
                    var opts = $(this).combobox('options');
                    return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
                }
            });
            $("#tandans_edpt_edit").combobox({
                url:'show/dept',
                type:'post',
                valueField:'deptid',
                textField:'dept',
                editable:false,
                panelWidth: 'auto',
                panelHeight: 'auto',
                filter: function(q, row){
                    var opts = $(this).combobox('options');
                    return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
                },
            });

            $('#tandans_couser_edit').combobox({
                url:'show/getCouserss',
                type:'post',
                valueField:'ID',
                textField:'CouserName',
                editable:false,
                panelWidth: 'auto',
                panelHeight: 'auto',
                filter: function(q, row){
                    var opts = $(this).combobox('options');
                    return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
                }
            });
            //回显


            $("#spantitle_fanans_edit").val(msg.content);
            $("#fandans_edit_ans").val(msg.ans)
            $("#tandans_col_edit").combobox('setValue',msg.collegeid);
            $("#tandans_edpt_edit").combobox('setValue',msg.deptid);
            $("#tandans_couser_edit").combobox('setValue',msg.courseid);
            $("#nddj_fandans_edit").combobox('setValue',msg.difficulty);
            $("#tandans_edit_des").val(msg.describes);
            $("#update_tandans_id").val(msg.id);
            $("#detailsans_edit").window('open');
        }
    });


}
function save_edit_tandans_des(){
    var id=$("#update_tandans_id").val()==null?"":$("#update_tandans_id").val();
    var title = $("#spantitle_fanans_edit").val()==null?"":$("#spantitle_fanans_edit").val();
    var des = $("#tandans_edit_des").val()==null?"":$("#tandans_edit_des").val().replace(/\s*/g,"").replace(/,/g, "").replace(/，/g, "");
    var col = $("#tandans_col_edit").combobox('getValue')==null?"":$("#tandans_col_edit").combobox('getValue');
    var dept = $("#tandans_edpt_edit").combobox('getValue')==null?"":$("#tandans_edpt_edit").combobox('getValue');
    var couser = $("#tandans_couser_edit").combobox('getValue')==null?"":$("#tandans_couser_edit").combobox('getValue');
    var nd = $("#nddj_fandans_edit").combobox('getValue')==null?"":$("#nddj_fandans_edit").combobox('getValue');
    var ans = $("#fandans_edit_ans").val()==null?"":$("#fandans_edit_ans").val();

    var obj = new Object();

    if(title==''){
        $.messager.alert("消息",'题目不可以为空');
        return;
    }
    obj.ID=id;
    obj.title=title;
    obj.des=des;
    obj.col=col;
    obj.dept=dept;
    obj.couser=couser;
    obj.nd=nd;
    obj.ans=ans;

    $.ajax({
        url : "/teacher/updatesubandlab",
        type : "post",
        dataType : "json",
        data : {datas:JSON.stringify(obj)},
        success : function(data) {
            if (data=="成功") {
                $.messager.alert("消息",'修改成功');
                findsub();
                $('#detailsans_edit').window('close');
            }else {
                $.messager.alert("消息",'修改未成功');
            }
        }
    });

}
function dwxx_formatter(value, row){
    if(value == undefined) {
        value = "";
    }
    return "<lable title='"+value+"'>"+value+"</lable>"
}

function showinput(){
    load();
    $("#inputbyUser").css('display','block');
}

function addmul(){
    var sel = 0;
    sel++;
    $("#foreach").append("<div class='appadd'><div class='widget-content'><div><h4>题目：</h4><textarea class='textarea' name='t1' rows='9' placeholder='题目输入不能为空'></textarea>难度等级<select   name='nddj' style='width:100px;' value=''>\n" +
        "                                                <option></option>\n" +
        "                                                <option value='高'>高</option>\n" +
        "                                                <option value='中'>中</option>\n" +
        "                                                <option value='低'>低</option>\n" +
        "                                            </select><div><h4>选项：</h4> A:<textarea class='textarea1' name='a'></textarea><br /> B:<textarea class='textarea1' name='b'></textarea><br /> C:<textarea class='textarea1' name='c'></textarea><br /> D:<textarea class='textarea1' name='d'></textarea><br /> E:<textarea class='textarea1' name='e'></textarea><br /> F:<textarea class='textarea1' name='f'></textarea><br /></div></div></div></div>");

}

function doSubmit() {
    $("#submitSelect").form({
        type : 'post',
        url : "teacher/inputmul",
        dataType : "json",
        success : function(result) {
            if (result=="success") {

                $.messager.alert('提示!', '导入成功','info',
                    function() {
                        var r = document.getElementsByName("appadd");
                        $('.appadd').remove();
                        $("#inputtrarea").val("");
                        $(".textarea1").val("")
                        showinput();
                    });
            } else {
                $.messager.confirm('提示',"导入失败!");

            }
        }
    });
    $("#submitSelect").submit();

}
function deptMag(){
    load();
    $("#showmul").css('display','block');

    initDataGrid();
}

function FAndTFMag(){
    load();
    $("#FAndTF").css('display','block');
    initDataGridFandTF();
}
function subMag(){
    load();
    $("#sub").css('display','block');
    initDataGridsub();
}
function openmul(id){
    console.info(id)
    var msg=new Object();
    $.ajax({
        url : "/teacher/getmulmsg",
        type : "post",
        dataType : "json",
        data : {id:id},
        success : function(msg) {
            var Title=msg.Title;
            if (Title!=undefined){
                $("#spantitle").html(Title)
            }
            var a=msg.A;
            if (a!=undefined){
                $("#chsa").css('display','block')
                $("#spana").html(a)
            }
            var b=msg.B;
            if (b!=undefined){
                $("#chsb").css('display','block')
                $("#spanb").html(b)
            }
            var c=msg.C;
            if (c!=undefined){
                $("#chsc").css('display','block')
                $("#spanc").html(c)
            }
            var d=msg.D;
            if (d!=undefined){
                $("#chsd").css('display','block')
                $("#spand").html(d)
            }
            var e=msg.E;
            if (e!=undefined){
                $("#chse").css('display','block')
                $("#spane").html(e)
            }
            var f=msg.F;
            if (f!=undefined){
                $("#chsf").css('display','block')
                $("#spanf").html(f)
            }
            $('#detailsmul').window('open');
        }
    });


}
function updateboxmul(msg){

    console.info(msg);

    $.ajax({
        url : "/teacher/getmulmsg",
        type : "post",
        dataType : "json",
        data : {id:msg},
        success : function(msg) {

            var Title=msg.Title;
            if (Title!=undefined){
                $("#spantitle_edit").val(Title)
            }
            var a=msg.A;
            if (a!=undefined){
                $("#chsa_edit").css('display','block')
                $("#spana_edit").val(a)
            }
            var b=msg.B;
            if (b!=undefined){
                $("#chsb_edit").css('display','block')
                $("#spanb_edit").val(b)
            }
            var c=msg.C;
            if (c!=undefined){
                $("#chsc_edit").css('display','block')
                $("#spanc_edit").val(c)
            }
            var d=msg.D;
            if (d!=undefined){
                $("#chsd_edit").css('display','block')
                $("#spand_edit").val(d)
            }
            var e=msg.E;
            if (e!=undefined){
                $("#chse_edit").css('display','block')
                $("#spane_edit").val(e)
            }
            var f=msg.F;
            if (f!=undefined){
                $("#chsf_edit").css('display','block')
                $("#spanf_edit").val(f)
            }

            $("#mul_col_edit").combobox({
                url:'show/getallcol',
                type:'post',
                valueField:'collegeid',
                textField:'college',
                editable:false,
                panelWidth: 'auto',
                panelHeight: 'auto',
                filter: function(q, row){
                    var opts = $(this).combobox('options');
                    return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
                }
            });
            $("#mul_edpt_edit").combobox({
                url:'show/dept',
                type:'post',
                valueField:'deptid',
                textField:'dept',
                editable:false,
                panelWidth: 'auto',
                panelHeight: 'auto',
                filter: function(q, row){
                    var opts = $(this).combobox('options');
                    return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
                },
            });

            $('#mul_couser_edit').combobox({
                url:'show/getCouserss',
                type:'post',
                valueField:'ID',
                textField:'CouserName',
                editable:false,
                panelWidth: 'auto',
                panelHeight: 'auto',
                filter: function(q, row){
                    var opts = $(this).combobox('options');
                    return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
                }
            });
            $("#mul_edit_des").val(msg.describes);

            $("#update_mul_id").val(msg.ID);
            $("#mul_col_edit").combobox('setValue',msg.collegeid);
            $("#mul_edpt_edit").combobox('setValue',msg.deptid);
            $("#mul_couser_edit").combobox('setValue',msg.courseid);
            $("#nddj_edit").combobox('setValue',msg.difficulty);

            //回显checkbox
            var boxObj = $("input:checkbox[name='ck']"); //获取所有的复选框值
            boxObj.each(function () {
                $(this).attr("checked",false);
            });
            var group=msg.Answer;
            console.info(group);
            if (group!=null) {
                $('#mul_ans_edit').combobox('setValues',group.split(","));
            }else {
                $('#mul_ans_edit').combobox('setValues',"");
            }

            $('#detailsmul_edit').window('open');
        }
    });
}

function save_edit_mul_des(){
    var id=$("#update_mul_id").val()==null?"":$("#update_mul_id").val();
    var title = $("#spantitle_edit").val()==null?"":$("#spantitle_edit").val().replace(/\s*/g,"").replace(/,/g, "").replace(/，/g, "");
    var a = $("#spana_edit").val()==null?"":$("#spana_edit").val().replace(/\s*/g,"").replace(/,/g, "").replace(/，/g, "");
    var b = $("#spanb_edit").val()==null?"":$("#spanb_edit").val().replace(/\s*/g,"").replace(/,/g, "").replace(/，/g, "");
    var c = $("#spanc_edit").val()==null?"":$("#spanc_edit").val().replace(/\s*/g,"").replace(/,/g, "").replace(/，/g, "");
    var d = $("#spand_edit").val()==null?"":$("#spand_edit").val().replace(/\s*/g,"").replace(/,/g, "").replace(/，/g, "");
    var e = $("#spane_edit").val()==null?"":$("#spane_edit").val().replace(/\s*/g,"").replace(/,/g, "").replace(/，/g, "");
    var f = $("#spanf_edit").val()==null?"":$("#spanf_edit").val().replace(/\s*/g,"").replace(/,/g, "").replace(/，/g, "");
    var des = $("#mul_edit_des").val()==null?"":$("#mul_edit_des").val().replace(/\s*/g,"").replace(/,/g, "").replace(/，/g, "");
    var col = $("#mul_col_edit").combobox('getValue')==null?"":$("#mul_col_edit").combobox('getValue');
    var dept = $("#mul_edpt_edit").combobox('getValue')==null?"":$("#mul_edpt_edit").combobox('getValue');
    var couser = $("#mul_couser_edit").combobox('getValue')==null?"":$("#mul_couser_edit").combobox('getValue');
    var nd = $("#nddj_edit").combobox('getValue')==null?"":$("#nddj_edit").combobox('getValue');
    var str = $("#mul_ans_edit").combobox('getText')==null?"":$("#mul_ans_edit").combobox('getText');

    var obj = new Object();
    if (title!=""){ obj.title=title}
    if (a!=""){obj.con1=a}
    if (b!=""){obj.con2=b}
    if (c!=""){obj.con3=c}
    if (d!=""){obj.con4=d}
    if (e!=""){obj.con5=e}
    if (f!=""){obj.con6=f}
    if (des!=""){obj.des=des}
    if (col!=""){obj.col=col}
    if (dept!=""){obj.dept=dept}
    if (couser!=""){obj.couser=couser}
    if (nd!=""){obj.nd=nd}
    obj.ans=str;
    obj.ID = id;

    console.info(obj);

    $.ajax({
        url : "/teacher/updatemulandlab",
        type : "post",
        dataType : "json",
        data : {datas:JSON.stringify(obj)},
        success : function(data) {
            if (data=="成功") {
            $.messager.alert("消息",'修改成功');
            findmul();
            $('#detailsmul_edit').window('close');
            }else {
                $.messager.alert("消息",'修改未成功');
            }
        }
    });

}
function course(){
    load();
    $("#couserDiv").css('display','block');
    initDataGridCouser();
}

function initDataGridCouser(){
    $('#teacherCouserbox').datagrid({
        width:'99.5%',
        height:408,
        remoteSort:false,
        iconCls : 'icon-search',
        columns : [[
            {
                field : 'ID',
                checkbox : true
            },
            {
                field : 'CouserName',
                title : '课程/方向',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            },
            {
                field : 'deptname',
                title : '所属专业',
                align:'center',
                sortable:true,
                formatter:dwxx_formatter
            }

        ]],
        onLoadSuccess:function(data){
        },
        rownumbers:true,
        pagination:true,
    });
    findteacherCouser();
}
function findteacherCouser(){
    var opts = $('#teacherCouserbox').datagrid("options");
    if(null == opts.url||""==opts.url){
        opts.url = '/teacher/findteacherCouser';
    }
    $('#teacherCouserbox').datagrid('load', {

    });
}
function showaddCouser(){
    $('#addCouserdept').combobox({
        url:'show/dept',
        type:'post',
        valueField:'deptid',
        textField:'dept',
        editable:false,
        panelWidth: 'auto',
        panelHeight: 'auto',
        filter: function(q, row){
            var opts = $(this).combobox('options');
            return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
        }
    });
    $('#addCouser').window('open');
}
function Couser_add_save(){
    var couser = $("#addCousername").val()==null?"":$("#addCousername").val().replace(/\s*/g,"").replace(/,/g, "").replace(/，/g, "");
    var deptid = $("#addCouserdept").combobox('getValue')==null?"":$("#addCouserdept").combobox('getValue');
    if (null==couser||couser==""){
        $.messager.alert("消息","请输入课程名");
        return;
    }
    if (null==deptid||deptid==""){
        $.messager.alert("消息","请选择专业");
        return;
    }
    $.ajax({
        url : "/teacher/addCouser",
        type : "post",
        dataType : "json",
        data : {deptid:deptid,couser:couser},
        success : function(data) {
            if (data=="添加成功"){
            $.messager.alert("消息",data);
            findteacherCouser();
            $('#addCouser').window('close');
            $("#addCousername").val('');

            }else {
                $.messager.alert("消息","添加失败");
            }
        }
    });
}
function showeditCouser(){
    var checkedItems = $('#teacherCouserbox').datagrid('getSelections');
    var selRow=$('#teacherCouserbox').datagrid('getSelected');
    if(checkedItems.length<1){
        $.messager.alert("消息","请选择要修改的行！");
        return;
    }
    if(checkedItems.length>1){
        $.messager.alert("消息","只可以修改一行！");
        return;
    }
    $("#edit_CouserID").val(selRow.ID);
    $("#editCousername").val(selRow.CouserName);
    $("#editCouserdept").combobox({
        url:'show/dept',
        type:'post',
        valueField:'deptid',
        textField:'dept',
        editable:false,
        panelWidth: 'auto',
        panelHeight: 'auto',
        filter: function(q, row){
            var opts = $(this).combobox('options');
            return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配
        },
        onLoadSuccess: function (){
            var data = $('#editCouserdept').combobox('getData');

            $('#editCouserdept').combobox('select',selRow.Secteurid);
        },
    });
    $('#editCouser').window('open');
}

function Couser_edit_save(){
    var id=$("#edit_CouserID").val()==null?"":$("#edit_CouserID").val();
    var couser = $("#editCousername").val()==null?"":$("#editCousername").val().replace(/\s*/g,"").replace(/,/g, "").replace(/，/g, "");
    var deptid = $("#editCouserdept").combobox('getValue')==null?"":$("#editCouserdept").combobox('getValue');

    $.ajax({
        url : "/teacher/editCouser",
        type : "post",
        dataType : "json",
        data : {deptid:deptid,couser:couser,id:id},
        success : function(data) {
            if (data=="修改成功"){
            $.messager.alert("消息",data);
            findteacherCouser();
            $('#editCouser').window('close');
            }else {
                $.messager.alert("消息","修改失败");
            }
        }
    });

}
function delCouser() {
    var checkedItems = $('#teacherCouserbox').datagrid('getSelections');
    if(checkedItems.length <= 0) {
        $.messager.alert('消息', "请选择一条数据！");
        return;
    }
    jQuery.messager.confirm('提示:', '删除后不可恢复,确定要操作！', function (event) {
        if (event) {
            var array = new Array()
            for(var i=0;i<checkedItems.length;i++){
                var obj = new Object();
                obj.ID = checkedItems[i].ID == null?"": checkedItems[i].ID+"";
                console.info(obj.ID);
                array.push(obj);

            }

            $.ajax({
                url : "/teacher/delCouser",
                type : "post",
                dataType : "json",
                data : {datas:JSON.stringify(array)},
                success : function(data) {
                    findteacherCouser();
                    $.messager.alert("消息",data);
                }
            });
        }
    });
}
function save_subquestion(msg,type){
    var text=msg;
    var type=type;
    var nd=$("#add_othernd").combobox('getValue')==null?"":$("#add_othernd").combobox('getValue');
    if (nd==""||nd==null) {
        alert("请选择难度");
        return;
    }
    if (text==""||text==null) {
        alert("请输入题目内容");
        return;
    }
    var obj = new Object();
    obj.tf=text;
    obj.nd=nd;
    obj.type=type;
    console.info(text);
    $.ajax({
        url : "/teacher/savesubquestion",
        type : "post",
        dataType : "json",
        data : {
            datas : JSON.stringify(obj)
        },
        success : function(data) {
            alert("保存成功");
            editor.txt.clear();
            $("#add_othernd").combobox('clear');
            $("#typexx").combobox('clear');
        }
    });



}

function updatepwd(){
 $("#updatepwd").window('open');

}
function save_pwd(){
    var id=$("#userid").val()==null?"":$("#userid").val();
    var old=$("#oldpwd").val()==null?"":$("#oldpwd").val();
    var new1=$("#newpwd").val()==null?"":$("#newpwd").val();
    var new2=$("#newpwd2").val()==null?"":$("#newpwd2").val();

    if (id.length<5&&id.length>19){
        $.messager.alert("消息","账号至少5个字符,最多18个字符");
        return;
    }
    if (old==''){
        $.messager.alert("消息","旧密码不能为空");
        return;
    }
    if (new1==''){
        $.messager.alert("消息","密码不能为空");
        return;
    }
    if (new2!=new1){
        $.messager.alert("消息","两次密码不相同");
        return;
    }

    $.ajax({
        url : "/teacher/save_pwd",
        type : "post",
        dataType : "json",
        data : {
            id : id,
            old:old,
            new:new2

        },
        success : function(data) {

        }
    });

}
function show_in_doc(){
    load();
    window.open('/importDoc','','left=200,top=100,width=400,height=200');
}
function show_in_txt(){
    load();
    window.open('/importTxt','','left=200,top=100,width=400,height=200');
}
function gb(msg){
    $("#"+msg+"").window('close');
}